package test;

import edu.iiist.web.beans.User;
import edu.iiist.web.dao.UserMgr;


public class dbtest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		//test DBSQL
		/*
		DBSQL sql = new DBSQL();
		//Object[] params = {"admin","hellosql"};
		sql.openDB(true,true);  
		ArrayList<Object[]> al = new ArrayList<Object[]>();  
		try{
			sql.prepareStatement("SELECT * FROM tbl_user WHERE Name = ? AND Psw = ?");
			//sql.setParams(params);
			sql.setString(1, "admin");
			sql.setString(2, "hellosql");
			ResultSet rs = sql.executeQuery();
			///////////////////////////////////////////////////////////////
			ResultSetMetaData rsmd = rs.getMetaData();  
			int column = rsmd.getColumnCount();  
               
			while (rs.next()) {  
				Object[] ob = new Object[column];  
				for (int i=1; i<=column; i++) 
				{  
					ob[i-1] = rs.getObject(i);  
				} 
				if(ob!=null) 
					al.add(ob);  
			}  
			rs.close();  
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			sql.closeDB();
		}
		
		Iterator<Object[]> iter = al.iterator();
		
		if(iter.hasNext())
		{
			Object[] rec = iter.next();
			
			String uid = rec[0].toString();
			String psw = rec[1].toString();
			String name = rec[2].toString();
			String birthday = rec[3].toString();
			String gender = rec[4].toString();
			String email = rec[5].toString();
			String phone = rec[6].toString();
			String title = rec[7].toString();
			String address = rec[8].toString();
			
			System.out.println(uid);
			System.out.println(psw);
			System.out.println(name);
			System.out.println(birthday);
			System.out.println(gender);
			System.out.println(email);
			System.out.println(phone);
			System.out.println(title);
			System.out.println(address);
					
		}*/
		              
			
		
		//test DBConnectionManager
		/*
		DBConnectionManager dd = DBConnectionManager.getInstance();
		try {
			Connection conn=dd.getDefaultConnection();
			
			dd.closeDefaultConnection(null, null, null);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/

		//test AddUser
		/*
		User user = new User();
		user.setName("abcd");
		user.setGender("f");
		user.setPsw("fdsafljdsa");
		user.setBirthday("19887655");
		user.setEmail("ddd@iiist.edu");
		user.setTitle("Student");
		user.setPhone("843975923");
		user.setAddress("SHANGHAI");
		
		UserMgr.AddUser(user);
		*/
			
		//test Login
		/*
		User user = UserMgr.Login("abcd", "fdsafljdsa");
		if(user!=null)
		{
			System.out.println(user.getID());
			System.out.println(user.getName());
			System.out.println(user.getPsw());
			System.out.println(user.getGender());
			System.out.println(user.getBirthday());
			System.out.println(user.getPhone());
			System.out.println(user.getTitle());
			System.out.println(user.getAddress());
			System.out.println(user.getEmail());
			
		}else
		{
			System.out.println("login failed");
		}
		*/
		//test DataBase
		/*
		String url = "jdbc:mysql://localhost/test";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			//
			con = DriverManager.getConnection(url, "root", "iiist");
			Statement select = con.createStatement( );
			ResultSet result = select.executeQuery("SELECT * FROM tbl_user");
			System.out.println("Results:");
			while(result.next( )) { // process results one row at a time
				String name;
				String manu;
				name = result.getString(1);
				if( result.wasNull( ) ) {
					name = null;
				}
				manu = result.getString(2);
				if( result.wasNull( ) ) {
					manu = null;
				}
				System.out.println(name + "|" + manu);
			}
		}catch( Exception e ) {
			e.printStackTrace( );
		}finally {
			if( con != null ) {
				try { con.close( ); }
				catch( Exception e ) { e.printStackTrace( ); }
			}
		}*/
		
		
	}
}
